/*=============================================================================
#    The element-comm is a tentative program used to test our ideas.           
#                       Copyright (C)  bgao                                    
#
#     This program is free software; you can redistribute it and/or            
#      modify it under the terms of the GNU General Public License             
#     as published by the Free Software Foundation; either version 2           
#         of the License, or (at your option) any later version.               
#
#     This program is distributed in the hope that it will be useful,          
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            
#             GNU General Public License for more details.                    
#
#    You should have received a copy of the GNU General Public License        
#     along with this program; if not, write to the Free Software             
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,             
#                       MA  02110-1301, USA.                                  
#==============================================================================
# $Id: mem.h 348 2010-11-29 09:01:16Z bgao $ 
#
# $Author: bgao $ 
#
# $Revision: 348 $ 
#
# $Date: 2010-11-29 17:01:16 +0800 (星期一, 29 十一月 2010) $ 
#
# Description: 
#
=============================================================================*/
/*! @file mem.h
 *  @brief This file provides the memory allocation interface.
 */
#ifndef _MEM_H_
#define _MEM_H_

#include "common.h"
#include "list.h"

#define MEM_ERR      -1;
#define MEM_OK        0;
#define MEM_NO_ITEM  -2;

/*! declare the mem and it's free list */
#define MEM(name) \
        LIST(name);

typedef list_t free_list; 

/*! define the pool type */
typedef struct _pool {
    void *ptr;     /*!< pointer to the pool buf */
    int num;       /*!< number of blocks in pool */ 
    int size;      /*!< size of each block in bytes */
} pool_t;

int8 mem_init(free_list list, pool_t *pool);
void *mem_alloc(free_list list);
int8 mem_free(free_list list, void *block);

#endif /* _MEM_H_ */
